<?php
return array(
	'parent' => array(
		'title' => 'Parent',
		'descr' => '',
		'type' => 'select',
		'bypost' => false,
		'load' => 'LoadParents',
		'save' => 'SaveParents',
		'options' => array(
			'exclude' => 0,
			'callback' => 'GetParents',
		),
	),
);
//RK
#Bad decision. Need move functions to class
function GetParents($a) {
	$mconfig = require_once Eleanor::FormatPath('modules/menu/config.php');
	$sel = Eleanor::Option('no', 0, in_array('', $a['value']));
	if(!class_exists($mconfig['api'], false))
		require_once Eleanor::FormatPath('modules/menu/api.php');
	$Plug = new $mconfig['api']($mconfig);
	$items = $Plug->GetOrderedList(false, false);
	foreach($items as &$v) {
		if($v['id']==$a['options']['exclude'] or strpos(','.$v['parents'],','.$a['options']['exclude'].',')!==false)
		continue;
		$sel.=Eleanor::Option(($v['parents'] ? str_repeat('&nbsp;',substr_count($v['parents'],',')).'›&nbsp;' : '').$v['title'],$v['id'],in_array($v['id'],$a['value']),array('style'=>$v['status']==0 ? 'color:gray;' : ''),2);
	}
	return$sel;
}

function SaveParents($a) {
	$mconfig = require_once Eleanor::FormatPath('modules/menu/config.php');
	$R = Eleanor::$Db->Query('SELECT `id`,`parents` FROM `'.$mconfig['t'].'` WHERE `id`='.(int)$a['value'].' LIMIT 1');
	if($a=$R->fetch_assoc())
	return $a['parents'] ? $a['parents'].$a['id'].',' : $a['id'].',';
	return'';
}

function LoadParents($a) {
	$a['value'] = rtrim($a['value'], ',');
	if(false !== $p = strrpos($a['value'], ','))
		$a['value'] = substr($a['value'], $p+1);
	return $a;
}
//RK END